from flask import make_response
from flask_restful import Api
from werkzeug.wrappers import Response

from redash.handlers.alerts import (
    AlertListResource,
    AlertResource,
    AlertNoreadResource,
    AlertReadResource,
    AlertMuteResource,
    AlertSubscriptionListResource,
    AlertSubscriptionResource,
)
from redash.handlers.base import org_scoped_rule
from redash.handlers.dashboards import (
    DashboardFavoriteListResource,
    DashboardListResource,
    DashboardResource,
    DashboardShareResource,
    DashboardTagsResource,
    PublicDashboardResource,
)
from redash.handlers.data_sources import (
    DataSourceListResource,
    DataSourcePauseResource,
    DataSourceResource,
    DataSourceSchemaResource,
    DataSourceTestResource,
    DataSourceTypeListResource,
)
from redash.handlers.databricks import (
    DatabricksDatabaseListResource,
    DatabricksSchemaResource,
    DatabricksTableColumnListResource,
)
from redash.handlers.destinations import (
    DestinationListResource,
    DestinationResource,
    DestinationdeleteResource,
    DestinationTypeListResource,
)
from redash.handlers.events import EventsResource
from redash.handlers.favorites import DashboardFavoriteResource, QueryFavoriteResource
from redash.handlers.groups import (
    GroupDataSourceListResource,
    GroupDataSourceResource,
    GroupListResource,
    GroupMemberListResource,
    GroupMemberResource,
    GroupResource,
)
from redash.handlers.permissions import (
    CheckPermissionResource,
    ObjectPermissionsListResource,
)
from redash.handlers.queries import (
    MyQueriesResource,
    QueryArchiveResource,
    QueryFavoriteListResource,
    QueryForkResource,
    QueryListResource,
    QueryRecentResource,
    QueryRefreshResource,
    QueryResource,
    QuerySearchResource,
    QueryTagsResource,
    QueryRegenerateApiKeyResource,
)
from redash.handlers.query_results import (
    JobResource,
    QueryResultDropdownResource,
    QueryDropdownsResource,
    QueryResultListResource,
    QueryResultResource,
    QueryUploadResource,
)
from redash.handlers.query_snippets import (
    QuerySnippetListResource,
    QuerySnippetResource,
)
from redash.handlers.settings import OrganizationSettings
from redash.handlers.users import (
    UserDisableResource,
    UserActiveResource,
    UserInviteResource,
    UserListResource,
    UserRegenerateApiKeyResource,
    UserResetPasswordResource,
    UserResource,
    UserdeleteResource,
)
from redash.handlers.visualizations import (
    VisualizationListResource,
    VisualizationResource,
)
from redash.handlers.widgets import WidgetListResource, WidgetResource
from redash.utils import json_dumps

from redash.handlers.enums import (
    EnumResource,
    EnumItemsResource,
    EnumAllResource,
    EnumdeleteResource,
)
from redash.handlers.orgunit import (
    OrgUnitListResource,
    OrgUnitListActiveResource,
    OrgUnitResource,
    OrgUnitdeleteResource,
    OrgUnitActiveResource,
    OrgUnitSelectResource,
    OrgUnitListnewResource,
)
from redash.handlers.orgstruct import (
    OrgStructListResource,
    OrgStructResource,
    OrgStructMatchResource,
    OrgStructdeleteResource,
)
from redash.handlers.timestruct import (
    TimeStructListResource,
    TimeStructResource,
)
from redash.handlers.timeserial import (
    TimeSerialListResource,
    TimeSerialsResource,
    TimeSerialResource,
    TimeSerialTree,
)
from redash.handlers.upload import (
    Uploadfile,
    Uploadcontracttextfile,
    Downloadfile,
    Removefile,
    Htmltopdf,
    Wordtopdf,
)
from redash.handlers.customertemp import (
    CustomerResource,
    CustomerListResource,
    CustomerNewResource,
    CustomerTempResource,
    CustomerTempdeleteResource,
    CustomerTempListResource,
    EmployeeResource,
    EmployeeListResource,
    DepartmentListResource,
    yusuancodeListResource,
    EmployeepurchaseListResource,
    EmployeeshenjiListResource,
)
from redash.handlers.contractapply import (
    ContractApplyNewResource,
    ContractApplycodeResource,
    ContractApplyResource,
    ContractApplyListResource,
    ContractPushBillResource,
    ContractApplydeleteResource,
)
from redash.handlers.workflow import (
    WorkflowResource,
    WorkflowUserResource,
    WorkfloweditResource,
    WorkflowmessageResource,
    WorkflowListResource,
    WorkflowNewResource,
    WorkflowUpdateResource,
    WorkflowUpdatedeleteResource,
    WorkflowUCopyResource,
    WorkflowcheckListResource,
    WorkflowcheckmessagResource,
)
from redash.handlers.workflow_bill_state import (
    Workflow_bill_stateNewResource,
    Workflow_bill_stateResource,
    Workflow_bill_statedeleteResource,
    Workflow_bill_stateListResource,
)
from redash.handlers.workflow_transition import (
    Workflow_transitionNewResource,
    Workflow_transitionResource,
    Workflow_transitiondeleteResource,
    Workflow_transitionListResource,
)
from redash.handlers.workflow_state import (
    Workflow_stateNewResource,
    Workflow_stateResource,
    Workflow_statedeleteResource,
    Workflow_stateListResource,
    Workflow_userListResource,
    Workflow_colListResource,
)
from redash.handlers.tabletype import (
    TabletypeNewResource,
    TabletypeResource,
    TabletypeListResource,
)
from redash.handlers.contracts import (
    ContractsNewResource,
    ContractsResource,
    ContractsListResource,
    ContractsActivityResource,
    ContractsSelListResource,
    ContractsSendmail,
    ContractsdeleteResource,
)
from redash.handlers.contractseal import (
    ContractSealNewResource,
    ContractSealResource,
    ContractSealListResource,
    ContractSealdeleteResource,
)
from redash.handlers.contractrecord import (
    ContractRecordNewResource,
    ContractRecordResource,
    ContractRecordListResource,
    ContractRecorddeleteResource,
)
from redash.handlers.contractchange import (
    ContractChangeNewResource,
    ContractChangeResource,
    ContractChangeListResource,
    ContractChangedeleteResource,
)
from redash.handlers.contractprogress import (
    ContractProgressNewResource,
    ContractProgressResource,
    ContractProgressListResource,
    ContractProgressdeleteResource,
)
from redash.handlers.contractsettle import (
    ContractSettleNewResource,
    ContractSettleResource,
    ContractSettleListResource,
    ContractSettledeleteResource,
)
from redash.handlers.contractstop import (
    ContractStopNewResource,
    ContractStopResource,
    ContractStopListResource,
    ContractStopdeleteResource,
)
from redash.handlers.contractfinish import (
    ContractFinishNewResource,
    ContractFinishResource,
    ContractFinishListResource,
    ContractFinishdeleteResource,
)
from redash.handlers.contractamount import (
    ContractAmountNewResource,
    ContractAmountResource,
    ContractAmountListResource,
    ContractAmountdeleteResource,
)
from redash.handlers.attaches import (
    AttachesNewResource,
    AttachesResource,
    AttachesListResource,
    AttachesListAllResource,
    AttachesListSelResource,
)
from redash.handlers.templates import (
    TemplatesNewResource,
    TemplatesResource,
    TemplatesdeleteResource,
    TemplatesListResource,
    TemplatestypeListResource,
)
from redash.handlers.globalsetting import (
    GlobalSettingNewResource,
    GlobalSettingResource,
    GlobalSettingListResource,
)
from redash.handlers.contractsuspend import (
    ContractSuspendNewResource,
    ContractSuspendResource,
    ContractSuspendListResource,
    ContractSuspenddeleteResource,
)
from redash.handlers.queryshowfield import (
    QueryShowFieldNewResource,
    QueryShowFieldResource,
    QueryShowFieldDeleteResource,
    QueryShowFieldListResource,
    QueryShowFieldCodeResource,
)
class ApiExt(Api):
    def add_org_resource(self, resource, *urls, **kwargs):
        urls = [org_scoped_rule(url) for url in urls]
        return self.add_resource(resource, *urls, **kwargs)


api = ApiExt()


@api.representation("application/json")
def json_representation(data, code, headers=None):
    # Flask-Restful checks only for flask.Response but flask-login uses werkzeug.wrappers.Response
    if isinstance(data, Response):
        return data
    resp = make_response(json_dumps(data), code)
    resp.headers.extend(headers or {})
    return resp


api.add_org_resource(AlertResource, "/api/alerts/<alert_id>", endpoint="alert")
api.add_org_resource(
    AlertMuteResource, "/api/alerts/<alert_id>/mute", endpoint="alert_mute"
)
api.add_org_resource(
    AlertSubscriptionListResource,
    "/api/alerts/<alert_id>/subscriptions",
    endpoint="alert_subscriptions",
)
api.add_org_resource(
    AlertSubscriptionResource,
    "/api/alerts/<alert_id>/subscriptions/<subscriber_id>",
    endpoint="alert_subscription",
)
api.add_org_resource(AlertListResource, "/api/alerts", endpoint="alerts")
api.add_org_resource(AlertNoreadResource, "/api/alerts/noread", endpoint="alert_noread")
api.add_org_resource(AlertReadResource, "/api/alerts/read/<alert_id>/<type>", endpoint="alert_read")


api.add_org_resource(DashboardListResource, "/api/dashboards", endpoint="dashboards")
api.add_org_resource(
    DashboardResource, "/api/dashboards/<dashboard_id>", endpoint="dashboard"
)
api.add_org_resource(
    PublicDashboardResource,
    "/api/dashboards/public/<token>",
    endpoint="public_dashboard",
)
api.add_org_resource(
    DashboardShareResource,
    "/api/dashboards/<dashboard_id>/share",
    endpoint="dashboard_share",
)

api.add_org_resource(
    DataSourceTypeListResource, "/api/data_sources/types", endpoint="data_source_types"
)
api.add_org_resource(
    DataSourceListResource, "/api/data_sources", endpoint="data_sources"
)
api.add_org_resource(
    DataSourceSchemaResource, "/api/data_sources/<data_source_id>/schema"
)
api.add_org_resource(
    DatabricksDatabaseListResource, "/api/databricks/databases/<data_source_id>"
)
api.add_org_resource(
    DatabricksSchemaResource,
    "/api/databricks/databases/<data_source_id>/<database_name>/tables",
)
api.add_org_resource(
    DatabricksTableColumnListResource,
    "/api/databricks/databases/<data_source_id>/<database_name>/columns/<table_name>",
)
api.add_org_resource(
    DataSourcePauseResource, "/api/data_sources/<data_source_id>/pause"
)
api.add_org_resource(DataSourceTestResource, "/api/data_sources/<data_source_id>/test")
api.add_org_resource(
    DataSourceResource, "/api/data_sources/<data_source_id>", endpoint="data_source"
)

api.add_org_resource(GroupListResource, "/api/groups", endpoint="groups")
api.add_org_resource(GroupResource, "/api/groups/<group_id>", endpoint="group")
api.add_org_resource(
    GroupMemberListResource, "/api/groups/<group_id>/members", endpoint="group_members"
)
api.add_org_resource(
    GroupMemberResource,
    "/api/groups/<group_id>/members/<user_id>",
    endpoint="group_member",
)
api.add_org_resource(
    GroupDataSourceListResource,
    "/api/groups/<group_id>/data_sources",
    endpoint="group_data_sources",
)
api.add_org_resource(
    GroupDataSourceResource,
    "/api/groups/<group_id>/data_sources/<data_source_id>",
    endpoint="group_data_source",
)

api.add_org_resource(EventsResource, "/api/events", endpoint="events")

api.add_org_resource(
    QueryFavoriteListResource, "/api/queries/favorites", endpoint="query_favorites"
)
api.add_org_resource(
    QueryFavoriteResource, "/api/queries/<query_id>/favorite", endpoint="query_favorite"
)
api.add_org_resource(
    DashboardFavoriteListResource,
    "/api/dashboards/favorites",
    endpoint="dashboard_favorites",
)
api.add_org_resource(
    DashboardFavoriteResource,
    "/api/dashboards/<object_id>/favorite",
    endpoint="dashboard_favorite",
)

api.add_org_resource(QueryTagsResource, "/api/queries/tags", endpoint="query_tags")
api.add_org_resource(
    DashboardTagsResource, "/api/dashboards/tags", endpoint="dashboard_tags"
)

api.add_org_resource(
    QuerySearchResource, "/api/queries/search", endpoint="queries_search"
)
api.add_org_resource(
    QueryRecentResource, "/api/queries/recent", endpoint="recent_queries"
)
api.add_org_resource(
    QueryArchiveResource, "/api/queries/archive", endpoint="queries_archive"
)
api.add_org_resource(QueryListResource, "/api/queries", endpoint="queries")
api.add_org_resource(MyQueriesResource, "/api/queries/my", endpoint="my_queries")
api.add_org_resource(
    QueryRefreshResource, "/api/queries/<query_id>/refresh", endpoint="query_refresh"
)
api.add_org_resource(QueryResource, "/api/queries/<query_id>", endpoint="query")
api.add_org_resource(
    QueryForkResource, "/api/queries/<query_id>/fork", endpoint="query_fork"
)
api.add_org_resource(
    QueryRegenerateApiKeyResource,
    "/api/queries/<query_id>/regenerate_api_key",
    endpoint="query_regenerate_api_key",
)

api.add_org_resource(
    ObjectPermissionsListResource,
    "/api/<object_type>/<object_id>/acl",
    endpoint="object_permissions",
)
api.add_org_resource(
    CheckPermissionResource,
    "/api/<object_type>/<object_id>/acl/<access_type>",
    endpoint="check_permissions",
)

api.add_org_resource(
    QueryResultListResource, "/api/query_results", endpoint="query_results"
)
api.add_org_resource(
    QueryResultDropdownResource,
    "/api/queries/<query_id>/dropdown",
    endpoint="query_result_dropdown",
)
api.add_org_resource(
    QueryDropdownsResource,
    "/api/queries/<query_id>/dropdowns/<dropdown_query_id>",
    endpoint="query_result_dropdowns",
)
api.add_org_resource(
    QueryResultResource,
    "/api/query_results/<query_result_id>.<filetype>",
    "/api/query_results/<query_result_id>",
    "/api/queries/<query_id>/results",
    "/api/queries/<query_id>/results.<filetype>",
    "/api/queries/<query_id>/results/<query_result_id>.<filetype>",
    endpoint="query_result",
)
api.add_org_resource(
    QueryUploadResource,"/api/queries/<datasource_id>/upload",endpoint="query_upload",
)
api.add_org_resource(
    JobResource,
    "/api/jobs/<job_id>",
    "/api/queries/<query_id>/jobs/<job_id>",
    endpoint="job",
)

api.add_org_resource(UserListResource, "/api/users", endpoint="users")
api.add_org_resource(UserResource, "/api/users/<user_id>", endpoint="user")
api.add_org_resource(UserdeleteResource, "/api/users/delete/<user_id>", endpoint="userdelete")

api.add_org_resource(
    UserInviteResource, "/api/users/<user_id>/invite", endpoint="user_invite"
)
api.add_org_resource(
    UserResetPasswordResource,
    "/api/users/<user_id>/reset_password",
    endpoint="user_reset_password",
)
api.add_org_resource(
    UserRegenerateApiKeyResource,
    "/api/users/<user_id>/regenerate_api_key",
    endpoint="user_regenerate_api_key",
)
api.add_org_resource(
    UserDisableResource, "/api/users/<user_id>/disable", endpoint="user_disable"
)
api.add_org_resource(
    UserActiveResource, "/api/users/<user_id>/active", endpoint="user_active"
)

api.add_org_resource(
    VisualizationListResource, "/api/visualizations", endpoint="visualizations"
)
api.add_org_resource(
    VisualizationResource,
    "/api/visualizations/<visualization_id>",
    endpoint="visualization",
)

api.add_org_resource(WidgetListResource, "/api/widgets", endpoint="widgets")
api.add_org_resource(WidgetResource, "/api/widgets/<int:widget_id>", endpoint="widget")

api.add_org_resource(
    DestinationTypeListResource, "/api/destinations/types", endpoint="destination_types"
)
api.add_org_resource(
    DestinationResource, "/api/destinations/<destination_id>", endpoint="destination"
)
api.add_org_resource(
    DestinationdeleteResource, "/api/destinationsdelete/<destination_id>", endpoint="destinationdelete"
)
api.add_org_resource(
    DestinationListResource, "/api/destinations", endpoint="destinations"
)

api.add_org_resource(
    QuerySnippetResource, "/api/query_snippets/<snippet_id>", endpoint="query_snippet"
)
api.add_org_resource(
    QuerySnippetListResource, "/api/query_snippets", endpoint="query_snippets"
)

api.add_org_resource(
    OrganizationSettings, "/api/settings/organization", endpoint="organization_settings"
)

api.add_org_resource(
    EnumResource, "/api/enums/<code>", endpoint="enum"
)
api.add_org_resource(
    EnumdeleteResource, "/api/enums/delete/<code>", endpoint="enumdelete"
)

api.add_org_resource(
    EnumItemsResource, "/api/enums/items/<code>", endpoint="enum_items"
)
api.add_org_resource(
    EnumAllResource, "/api/enums/all", endpoint="enum_all"
)

api.add_org_resource(
    OrgUnitListResource, "/api/orgunit", endpoint="orgunits"
)

api.add_org_resource(
    OrgUnitListnewResource, "/api/orgunitlist", endpoint="orgunitlist"
)

api.add_org_resource(
    OrgUnitListActiveResource, "/api/orgunitactive", endpoint="orgunitsactive"
)
api.add_org_resource(
    OrgUnitResource, "/api/orgunit/<orgunit_id>", endpoint="orgunit"
)
api.add_org_resource(
    OrgUnitdeleteResource, "/api/orgunit/delete/<orgunit_id>", endpoint="orgunitdelete"
)

api.add_org_resource(
    OrgUnitActiveResource, "/api/orgunit/active/<orgunit_id>", endpoint="orgunit_active"
)
api.add_org_resource(
    OrgUnitSelectResource, "/api/orgunit/select/<orgstruct_id>", endpoint="orgunit_select"
)

api.add_org_resource(
    OrgStructListResource, "/api/orgstructs/<orgstruct_enum>", endpoint="orgstructs"
)
api.add_org_resource(
    OrgStructResource, "/api/orgstruct/<orgstruct_id>", endpoint="orgstruct"
)
api.add_org_resource(
    OrgStructdeleteResource, "/api/orgstruct/delete/<orgstruct_id>", endpoint="orgstructdelete"
)

api.add_org_resource(
    OrgStructMatchResource, "/api/orgstruct/match/<orgstruct_enum>", endpoint="orgstruct_match"
)
api.add_org_resource(
    TimeStructResource, "/api/timestruct/<id>", endpoint="timestruct_id"
)
api.add_org_resource(
    TimeStructListResource, "/api/timestructs/<calendar_enum>", endpoint="timestruct_list"
)
api.add_org_resource(
    TimeSerialListResource, "/api/timeserial/<parent_id>/<timestruct_id>", endpoint="timeseriallist"
)
api.add_org_resource(
    TimeSerialsResource, "/api/timeserial", endpoint="timeserials"
)
api.add_org_resource(
    TimeSerialResource, "/api/timeserial/<timeserial_id>", endpoint="timeserial"
)
api.add_org_resource(
    Uploadfile, "/api/upload/uploadfile/<sourcetype>/<types>/<bytstatus>/<nature>/<sourceid>", endpoint="uploadfile"
)
api.add_org_resource(
    Uploadcontracttextfile, "/api/upload/uploadcontracttextfile/<contract_id>", endpoint="uploadcontracttextfile"
)

api.add_org_resource(
    Downloadfile, "/api/upload/downloadfile", endpoint="downloadfile"
)
api.add_org_resource(
    Removefile, "/api/upload/removefile/<sourcetype>/<sourceid>/<uid>", endpoint="removefile"
)
api.add_org_resource(
    Htmltopdf, "/api/upload/htmltopdf", endpoint="htmltopdf"
)
api.add_org_resource(
    Wordtopdf, "/api/upload/wordtopdf", endpoint="wordtopdf"
)

api.add_org_resource(
    CustomerResource, "/api/customer/<code>", endpoint="customer"
)
api.add_org_resource(
    CustomerTempListResource, "/api/customertemp/list/<bytstatus>", endpoint="customertemplist"
)

api.add_org_resource(
    CustomerNewResource, "/api/customertemp", endpoint="customertempnew"
)
api.add_org_resource(
    CustomerTempResource, "/api/customertemp/<customertemp_id>", endpoint="customertemp"
)
api.add_org_resource(
    CustomerTempdeleteResource, "/api/customertemp/delete/<customertemp_id>", endpoint="customertempdelete"
)
api.add_org_resource(
    CustomerListResource, "/api/customertemp/list", endpoint="customerlist"
)

api.add_org_resource(
    EmployeeResource, "/api/employeetemp/<code>", endpoint="employee"
)
api.add_org_resource(
    EmployeeListResource, "/api/employeetemp/list", endpoint="employeelist"
)
api.add_org_resource(
    EmployeepurchaseListResource, "/api/purchaseemployeetemp/list", endpoint="purchaseemployeelist"
)
api.add_org_resource(
    EmployeeshenjiListResource, "/api/shenjiemployeetemp/list", endpoint="shenjiemployeelist"
)
api.add_org_resource(
        TimeSerialTree, "/api/timeserial/tree/<timeserialstatus_enum>", endpoint="timeserialtree"
)
api.add_org_resource(
    DepartmentListResource, "/api/department/list", endpoint="departmentlist"
)
api.add_org_resource(
    yusuancodeListResource, "/api/yusuancode/list", endpoint="yusuancodelist"
)
api.add_org_resource(
    ContractApplyNewResource, "/api/contractapply", endpoint="contractapplynew"
)
api.add_org_resource(
    ContractApplycodeResource, "/api/contractapply/code", endpoint="contractapplycode"
)
api.add_org_resource(
    ContractApplyResource, "/api/contractapply/<contractapply_id>", endpoint="contractapply"
)
api.add_org_resource(
    ContractApplyListResource, "/api/contractapply/list", endpoint="contractapplylist"
)
api.add_org_resource(
    ContractApplydeleteResource, "/api/contractapply/delete/<contractapply_id>", endpoint="contractapplydelete"
)

api.add_org_resource(
    ContractPushBillResource, "/api/contractpushbill", endpoint="contractpushbill"
)
api.add_org_resource(
    Workflow_bill_stateNewResource, "/api/workflow_bill_state", endpoint="workflow_bill_statenew"
)
api.add_org_resource(
    Workflow_bill_stateResource, "/api/workflow_bill_state/<workflow_bill_state_id>", endpoint="workflow_bill_state"
)
api.add_org_resource(
    Workflow_bill_statedeleteResource, "/api/workflow_bill_state/delete/<workflow_bill_state_id>", endpoint="workflow_bill_statedelete"
)

api.add_org_resource(
    Workflow_bill_stateListResource, "/api/workflow_bill_state/list", endpoint="workflow_bill_statelist"
)
api.add_org_resource(
    Workflow_transitionNewResource, "/api/workflow_transition", endpoint="workflow_transitionnew"
)
api.add_org_resource(
    Workflow_transitionResource, "/api/workflow_transition/<workflow_transition_id>", endpoint="workflow_transition"
)
api.add_org_resource(
    Workflow_transitiondeleteResource, "/api/workflow_transition/delete/<workflow_transition_id>", endpoint="workflow_transitiondelete"
)

api.add_org_resource(
    Workflow_transitionListResource, "/api/workflow_transition/list", endpoint="workflow_transitionlist"
)
api.add_org_resource(
    Workflow_stateNewResource, "/api/workflow_state", endpoint="workflow_statenew"
)
api.add_org_resource(
    Workflow_stateResource, "/api/workflow_state/<workflow_state_id>", endpoint="workflow_state"
)
api.add_org_resource(
    Workflow_statedeleteResource, "/api/workflow_state/delete/<workflow_state_id>", endpoint="workflow_statedelete"
)

api.add_org_resource(
    Workflow_stateListResource, "/api/workflow_state/list", endpoint="workflow_statelist"
)
api.add_org_resource(
    Workflow_userListResource, "/api/workflow_user/list", endpoint="workflow_userlist"
)
api.add_org_resource(
    Workflow_colListResource, "/api/workflow_col/list", endpoint="workflow_collist"
)
api.add_org_resource(
    WorkflowResource, "/api/workflow/check", endpoint="workflowcheck"
)
api.add_org_resource(
    WorkflowUserResource, "/api/workflow/user", endpoint="workflowuser"
)
api.add_org_resource(
    WorkfloweditResource, "/api/workflow/edit/<bill>/<billtype>/<billid>/<userid>", endpoint="workflowcheckedit"
)
api.add_org_resource(
    WorkflowmessageResource, "/api/workflow/message/<bill>/<billid>/<bill_type>/<orgunitid>", endpoint="workflowmessage"
)
api.add_org_resource(
    WorkflowListResource, "/api/workflow/list", endpoint="workflowlist"
)
api.add_org_resource(
    WorkflowcheckListResource, "/api/workflow/checkList", endpoint="workflowchecklist"
)
api.add_org_resource(
    WorkflowcheckmessagResource, "/api/workflow/checkmessag", endpoint="workflowcheckmessag"
)

api.add_org_resource(
    WorkflowNewResource, "/api/workflow", endpoint="workflownew"
)
api.add_org_resource(
    WorkflowUpdateResource, "/api/workflow/<workflow_id>", endpoint="workflow"
)
api.add_org_resource(
    WorkflowUpdatedeleteResource, "/api/workflow/delete/<workflow_id>", endpoint="workflowdelete"
)
api.add_org_resource(
    WorkflowUCopyResource, "/api/workflow/copy/<workflow_id>/<userid>", endpoint="workflowcopy"
)
api.add_org_resource(
    ContractsNewResource, "/api/contracts", endpoint="contractsnew"
)
api.add_org_resource(
    ContractsResource, "/api/contracts/<contracts_id>", endpoint="contracts"
)
api.add_org_resource(
    ContractsdeleteResource, "/api/contracts/delete/<contracts_id>", endpoint="contractsdelete"
)
api.add_org_resource(
    ContractsListResource, "/api/contracts/list", endpoint="contractslist"
)
api.add_org_resource(
    ContractsSelListResource, "/api/contracts/sellist", endpoint="contractssellist"
)
api.add_org_resource(
    ContractsSendmail, "/api/contracts/sendmail", endpoint="contractssendmail"
)
api.add_org_resource(
    ContractsActivityResource, "/api/contractsactivity/<contracts_id>/<sourcetype>", endpoint="contractsactivity"
)

api.add_org_resource(
    ContractSealNewResource, "/api/contractseal", endpoint="contractsealnew"
)
api.add_org_resource(
    ContractSealResource, "/api/contractseal/<contractseal_id>", endpoint="contractseal"
)
api.add_org_resource(
    ContractSealdeleteResource, "/api/contractseal/delete/<contractseal_id>", endpoint="contractsealdelete"
)

api.add_org_resource(
    ContractSealListResource, "/api/contractseal/list", endpoint="contractseallist"
)
api.add_org_resource(
    ContractRecordNewResource, "/api/contractrecord", endpoint="contractrecordnew"
)
api.add_org_resource(
    ContractRecordResource, "/api/contractrecord/<contractrecord_id>", endpoint="contractrecord"
)
api.add_org_resource(
    ContractRecorddeleteResource, "/api/contractrecord/delete/<contractrecord_id>", endpoint="contractrecorddelete"
)
api.add_org_resource(
    ContractRecordListResource, "/api/contractrecord/list", endpoint="contractrecordlist"
)
api.add_org_resource(
    ContractChangeNewResource, "/api/contractchange", endpoint="contractchangenew"
)
api.add_org_resource(
    ContractChangeResource, "/api/contractchange/<contractchange_id>", endpoint="contractchange"
)
api.add_org_resource(
    ContractChangedeleteResource, "/api/contractchange/delete/<contractchange_id>", endpoint="contractchangedelete"
)
api.add_org_resource(
    ContractChangeListResource, "/api/contractchange/list", endpoint="contractchangelist"
)
api.add_org_resource(
    ContractProgressNewResource, "/api/contractprogress", endpoint="contractprogressnew"
)
api.add_org_resource(
    ContractProgressResource, "/api/contractprogress/<contractprogress_id>", endpoint="contractprogress"
)
api.add_org_resource(
    ContractProgressdeleteResource, "/api/contractprogress/delete/<contractprogress_id>", endpoint="contractprogressdelete"
)
api.add_org_resource(
    ContractProgressListResource, "/api/contractprogress/list", endpoint="contractprogresslist"
)

api.add_org_resource(
    ContractSettleNewResource, "/api/contractsettle", endpoint="contractsettlenew"
)
api.add_org_resource(
    ContractSettleResource, "/api/contractsettle/<contractsettle_id>", endpoint="contractsettle"
)
api.add_org_resource(
    ContractSettledeleteResource, "/api/contractsettle/delete/<contractsettle_id>", endpoint="contractsettledelete"
)

api.add_org_resource(
    ContractSettleListResource, "/api/contractsettle/list", endpoint="contractsettlelist"
)
api.add_org_resource(
    ContractStopNewResource, "/api/contractstop", endpoint="contractstopnew"
)
api.add_org_resource(
    ContractStopResource, "/api/contractstop/<contractstop_id>", endpoint="contractstop"
)
api.add_org_resource(
    ContractStopdeleteResource, "/api/contractstop/delete/<contractstop_id>", endpoint="contractstopdelete"
)

api.add_org_resource(
    ContractStopListResource, "/api/contractstop/list", endpoint="contractstoplist"
)
api.add_org_resource(
    ContractFinishNewResource, "/api/contractfinish", endpoint="contractfinishnew"
)
api.add_org_resource(
    ContractFinishResource, "/api/contractfinish/<contractfinish_id>", endpoint="contractfinish"
)
api.add_org_resource(
    ContractFinishdeleteResource, "/api/contractfinish/delete/<contractfinish_id>", endpoint="contractfinishdelete"
)

api.add_org_resource(
    ContractFinishListResource, "/api/contractfinish/list", endpoint="contractfinishlist"
)
api.add_org_resource(
    ContractAmountNewResource, "/api/contractamount", endpoint="contractamountnew"
)
api.add_org_resource(
    ContractAmountResource, "/api/contractamount/<contractamount_id>", endpoint="contractamount"
)
api.add_org_resource(
    ContractAmountdeleteResource, "/api/contractamount/delete/<contractamount_id>", endpoint="contractamountdelete"
)
api.add_org_resource(
    ContractAmountListResource, "/api/contractamount/list", endpoint="contractamountlist"
)
api.add_org_resource(
    AttachesNewResource, "/api/attaches", endpoint="attachesnew"
)
api.add_org_resource(
    AttachesResource, "/api/attaches/<source_id>/<source_type>", endpoint="attaches"
)
api.add_org_resource(
    AttachesListResource, "/api/attaches/list", endpoint="attacheslist"
)
api.add_org_resource(
    AttachesListAllResource, "/api/attaches/listall", endpoint="attacheslistall"
)
api.add_org_resource(
    AttachesListSelResource, "/api/attaches/listsel", endpoint="attacheslistsel"
)
api.add_org_resource(
    TemplatesNewResource, "/api/templates", endpoint="templatesnew"
)
api.add_org_resource(
    TemplatesResource, "/api/templates/<templates_id>", endpoint="templates"
)
api.add_org_resource(
    TemplatesdeleteResource, "/api/templates/delete/<templates_id>", endpoint="templatesdelete"
)

api.add_org_resource(
    TemplatesListResource, "/api/templates/list", endpoint="templateslist"
)
api.add_org_resource(
    TemplatestypeListResource, "/api/templates/type/list", endpoint="templatestypelist"
)
api.add_org_resource(
    TabletypeNewResource, "/api/tabletype", endpoint="tabletypenew"
)
api.add_org_resource(
    TabletypeResource, "/api/tabletype/<tabletype_id>", endpoint="tabletype"
)
api.add_org_resource(
    TabletypeListResource, "/api/tabletype/list", endpoint="tabletypelist"
)

api.add_org_resource(
    GlobalSettingNewResource, "/api/globalsetting", endpoint="globalsettingnew"
)
api.add_org_resource(
    GlobalSettingResource, "/api/globalsetting/<globalsetting_id>", endpoint="globalsetting"
)
api.add_org_resource(
    GlobalSettingListResource, "/api/globalsetting/list", endpoint="globalsettinglist"
)
api.add_org_resource(
    ContractSuspendNewResource, "/api/contractsuspend", endpoint="contractsuspendnew"
)
api.add_org_resource(
    ContractSuspendResource, "/api/contractsuspend/<contractsuspend_id>", endpoint="contractsuspend"
)
api.add_org_resource(
    ContractSuspenddeleteResource, "/api/contractsuspend/delete/<contractsuspend_id>", endpoint="contractsuspenddelete"
)

api.add_org_resource(
    ContractSuspendListResource, "/api/contractsuspend/list", endpoint="contractsuspendlist"
)
api.add_org_resource(
    QueryShowFieldNewResource, "/api/queryshowfield", endpoint="queryshowfieldnew"
)
api.add_org_resource(
    QueryShowFieldResource, "/api/queryshowfield/<queryshowfield_id>", endpoint="queryshowfield"
)
api.add_org_resource(
    QueryShowFieldCodeResource, "/api/queryshowfieldcode/<queryshowfield_code>", endpoint="queryshowfieldcode"
)

api.add_org_resource(
    QueryShowFieldDeleteResource, "/api/queryshowfield/delete/<queryshowfield_id>", endpoint="queryshowfielddelete"
)
api.add_org_resource(
    QueryShowFieldListResource, "/api/queryshowfield/list", endpoint="queryshowfieldlist"
)